#include <gtest/gtest.h>

#include <climits>
#include <cstddef>

#include "hash_table/hash_table.h"

class HashTableTest : public ::testing::Test
{
  protected:
    void SetUp() override
    {
        // 初始化代码 (需要时)
    }
};

TEST_F(HashTableTest, BasicInsertAndFind)
{
    HashTable<int, int> table;
    table.insert(1, 21);
    int value = INT_MIN;
    EXPECT_TRUE(table.find(1, value));  // 检查存在性
    EXPECT_EQ(value, 21);               // 检查值
    EXPECT_EQ(table.size(), 1);
}

TEST_F(HashTableTest, ResizeTest)
{
    HashTable<int, int> table;
    for (int i = 1; i <= 12; ++i)
    {
        table.insert(i, 20 + i);
    }
    EXPECT_TRUE(table.getBucketCount() == 16);
    EXPECT_TRUE(table.size() == 12);
    table.insert(13, 20 + 13);
    EXPECT_TRUE(table.getBucketCount() == 32);
    EXPECT_TRUE(table.size() == 13);

    int value = INT_MIN;
    EXPECT_TRUE(table.find(2, value) && value == 22);
    table.remove(2);
    EXPECT_TRUE(table.getBucketCount() == 32);
    EXPECT_TRUE(!table.find(2, value));
    EXPECT_TRUE(table.size() == 12);
}